home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / clntform.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  3.3 KB  |  116 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. /* This program works in conjunction with the Monitor.mak project to demonstrate
  6.   advanced Win32 programming topics.  See Monform.cpp for more information */
  7. //--------------------------------------------------------------------------
  8. #include <vcl.h>
  9. #pragma hdrstop
  10. //--------------------------------------------------------------------------
  11. #include "clntform.h"
  12.  
  13. #pragma resource "*.DFM"
  14.  
  15. TClientForm*  ClientForm;
  16. __fastcall TClientForm::TClientForm(TComponent* Owner) : TForm(Owner)
  17. {
  18. }
  19.  
  20. void __fastcall TClientForm::FormCreate(TObject* Sender)
  21. {
  22.   int  CNo, VCnt;
  23.  
  24.   String buf(Application->Title);
  25.   buf += " ";
  26.   buf += (int)GetCurrentProcessId();
  27.  
  28.   Caption = buf;
  29.  
  30.   try {
  31.     IPCClient = new TIPCClient(GetCurrentProcessId(), Caption);
  32.     IPCClient->OnConnect = OnConnect;
  33.     IPCClient->OnSignal = OnSignal;
  34.     IPCClient->Activate();
  35.     if (! (IPCClient->State == stConnected))
  36.       OnConnect(NULL, false);
  37.     VCnt = Screen->Height / (Height + 10);
  38.     CNo = IPCClient->ClientCount() - 1;
  39.     Top = (CNo % VCnt) * (Height + 10) + 10;
  40.     Left = (Screen->Width / 2) + (CNo / VCnt) * (Width + 10);
  41.   }
  42.   catch(...){
  43.     Application->Terminate();
  44.   }
  45. }
  46.  
  47. void __fastcall TClientForm::FormDestroy( TObject* Sender)
  48. {
  49.   IPCClient->Free();
  50. }
  51.  
  52. void __fastcall TClientForm::OnConnect(TIPCThread* Sender, bool Connecting)
  53. {
  54.   PostMessage(Handle, WM_UPDATESTATUS, WPARAM(Connecting), 0);
  55. }
  56.  
  57. void __fastcall TClientForm::OnSignal(TIPCThread* Sender, const TEventData &Data)
  58. {
  59.   Flags = Data.Flags;
  60. }
  61.  
  62. void __fastcall TClientForm::FormMouseMove( TObject* Sender,
  63.                                             TShiftState Shift,
  64.                                             int X, int  Y)
  65. {
  66.   TEventData  EventData;
  67.  
  68.   if (Flags.Contains(cfMouseMove) == true){
  69.       EventData.X = (short) X;
  70.       EventData.Y = (short) Y;
  71.       EventData.Flag = cfMouseMove;
  72.       IPCClient->SignalMonitor(EventData);
  73.   }
  74. }
  75.  
  76. void __fastcall TClientForm::FormMouseDown( TObject* Sender,
  77.                                             TMouseButton Button,
  78.                                             TShiftState  Shift,
  79.                                             int X, int Y)
  80. {
  81.   TEventData  EventData;
  82.  
  83.   if (Flags.Contains(cfMouseMove) == true) {
  84.       EventData.X = (short) X;
  85.       EventData.Y = (short) Y;
  86.       EventData.Flag = cfMouseDown;
  87.       IPCClient->SignalMonitor(EventData);
  88.   }
  89. }
  90.  
  91. void __fastcall TClientForm::FormResize(TObject* Sender)
  92. {
  93.   TEventData  EventData;
  94.  
  95.   if (Flags.Contains(cfResize) == true){
  96.       EventData.X = (short) Width;
  97.       EventData.Y = (short) Height;
  98.       EventData.Flag = cfResize;
  99.       IPCClient->SignalMonitor(EventData);
  100.   }
  101. }
  102.  
  103. void __fastcall TClientForm::FormClick(TObject* Sender)
  104. {
  105.   if (IPCClient->State != stConnected)
  106.       IPCClient->MakeCurrent();
  107. }
  108.  
  109. void __fastcall TClientForm::UpdateStatusBar(TMessage* Msg)
  110. {
  111.   PChar ConnectStr[2] = {"Not Connected", "Connected"};
  112.  
  113.   StatusBar->SimpleText = ConnectStr[Msg->WParam];
  114. }
  115.  
  116.